package com.codbking.calendar.exaple;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;

import static android.R.attr.textSize;

//+0002361
public class ListHeaderView extends View {
    private TextPaint paint;
    private Paint paint1;
    private float density;

    public ListHeaderView(Context context) {
        super(context);
        init();
    }

    public ListHeaderView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
//        Shader shader = new LinearGradient(0, 0, 10, 10, new int[]{}, null, Shader.TileMode.REPEAT);
        density = getResources().getDisplayMetrics().density;
        paint = new TextPaint();
        paint.setColor(Color.BLACK);
        paint.setStrokeWidth(2);
        paint.setAntiAlias(true);
        paint.setTextSize(getResources().getDisplayMetrics().density * textSize);

        paint1 = new Paint();
        paint1.setColor(Color.BLACK);
        paint1.setStyle(Paint.Style.FILL);
    }

    public ListHeaderView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint1.setColor(Color.RED);
        setLayerType(LAYER_TYPE_SOFTWARE, null);
        paint1.setShadowLayer(getPxByDp(3), 0, getPxByDp(1), Color.GRAY);
        canvas.drawRect(0, 0, getWidth() / 2, getHeight() / 2, paint1);

        paint.setColor(Color.BLACK);
        canvas.drawLine(getWidth() / 2 - getPxByDp(10), getPxByDp(5), getWidth() / 2 + getPxByDp(10), getPxByDp(5), paint);
        canvas.drawLine(getWidth() / 2 - getPxByDp(10), getPxByDp(10), getWidth() / 2 + getPxByDp(10), getPxByDp(10), paint);
        paint.setColor(Color.BLACK);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int width = MeasureSpec.getSize(widthMeasureSpec);
        int height = getPxByDp(MeasureSpec.getSize(heightMeasureSpec));
        setMeasuredDimension(width, height);
    }

    private int getPxByDp(int dp) {
        return (int) (dp * density);
    }
}
